package com.estate.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;

import com.estate.dao.ContractFileDao;
import com.estate.vo.Vo;
import com.estate.vo.impl.ContractFileVo;
import com.estate.vo.impl.ContractVo;

public class ContractFileDaoImpl implements ContractFileDao {

private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	

	public boolean addVo(Vo vo) {
		this.getSessionFactory().getCurrentSession().save(vo);
		return true;
	}

	public boolean deleteVo(Vo vo) {
		this.getSessionFactory().getCurrentSession().delete(vo);
		return false;
	}

	public List<Vo> findAll() {
		Query query = this.getSessionFactory().getCurrentSession().createQuery("from ContractFileVo");
		List<Vo> voList = query.list();
		return voList;
	}

	public Vo findByPK(Object pk) {
		Vo vo = (Vo) this.getSessionFactory().getCurrentSession().get(ContractFileVo.class, (Integer)pk);
		return vo;
	}

	public boolean updateVo(Vo vo) {
		this.getSessionFactory().getCurrentSession().update(vo);
		return false;
	}

	public void deleteByContractId(int contractId) {
		// TODO Auto-generated method stub
		Query query = this.getSessionFactory().getCurrentSession().createQuery("from ContractFileVo where contractId=:contractId").setInteger("contractId", contractId);
		List<Vo> voList = query.list();
		for(int i=0;i<voList.size();i++){
			this.deleteVo(voList.get(i));
		}
	}

	public List<Vo> findByContractId(int contractId) {
		// TODO Auto-generated method stub
		Query query = this.getSessionFactory().getCurrentSession().createQuery("from ContractFileVo where contractId=:contractId").setInteger("contractId", contractId);
		List<Vo> voList = query.list();
		return voList;
	}

}
